package com.daou.smartpush.common.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.daou.smartpush.common.util.Message;
import com.daou.smartpush.domain.company.Company;

public class CreateCompanyValidator implements Validator{

	@Override
	public boolean supports(Class<?> clazz) {
		return CreateCompanyValidator.class.isAssignableFrom(clazz);
	}

	@Override
	public void validate(Object target, Errors errors) {
		Company company = (Company) target;
		
		if(company.getCompanyName().trim().isEmpty()){
			ValidationUtils.rejectIfEmptyOrWhitespace(errors, "error_msg", "required",
                    Message.getMessage("warning.company.emptyCompanyName"));
		}else if (company.getTel1().trim().isEmpty()) {
			ValidationUtils.rejectIfEmptyOrWhitespace(errors, "error_msg", "required",
                    Message.getMessage("warning.company.emptyTel"));
		}else if (company.getTel2().trim().isEmpty()) {
			ValidationUtils.rejectIfEmptyOrWhitespace(errors, "error_msg", "required",
                    Message.getMessage("warning.company.emptyTel"));
		}else if (company.getTel3().trim().isEmpty()) {
			ValidationUtils.rejectIfEmptyOrWhitespace(errors, "error_msg", "required",
                    Message.getMessage("warning.company.emptyTel"));
		}else if (company.getEmail().trim().isEmpty()) {
			ValidationUtils.rejectIfEmptyOrWhitespace(errors, "error_msg", "required",
                    Message.getMessage("warning.company.emptyEmail"));
		}
	}
}
